home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / web / aspmaker / setup.exe / %MAINDIR% / src / popcalendar.js < prev   
Encoding:
JavaScript  |  2003-08-28  |  21.4 KB  |  613 lines

  1. //    written    by Tan Ling    Wee    on 2 Dec 2001
  2. //    last updated 23 June 2002
  3. //    email :    fuushikaden@yahoo.com
  4.  
  5.     var    fixedX = -1            // x position (-1 if to appear below control)
  6.     var    fixedY = -1            // y position (-1 if to appear below control)
  7.     var startAt = 0            // 0 - sunday ; 1 - monday
  8.     var showWeekNumber = 0    // 0 - don't show; 1 - show
  9.     var showToday = 1        // 0 - don't show; 1 - show
  10.     var imgDir = "images/"            // directory for images ... e.g. var imgDir="/img/"
  11.  
  12.     var gotoString = "Go To Current Month"
  13.     var todayString = "Today is"
  14.     var weekString = "Wk"
  15.     var scrollLeftMessage = "Click to scroll to previous month. Hold mouse button to scroll automatically."
  16.     var scrollRightMessage = "Click to scroll to next month. Hold mouse button to scroll automatically."
  17.     var selectMonthMessage = "Click to select a month."
  18.     var selectYearMessage = "Click to select a year."
  19.     var selectDateMessage = "Select [date] as date." // do not replace [date], it will be replaced by date.
  20.  
  21.     var    crossobj, crossMonthObj, crossYearObj, monthSelected, yearSelected, dateSelected, omonthSelected, oyearSelected, odateSelected, monthConstructed, yearConstructed, intervalID1, intervalID2, timeoutID1, timeoutID2, ctlToPlaceValue, ctlNow, dateFormat, nStartingYear
  22.  
  23.     var    bPageLoaded=false
  24.     var    ie=document.all
  25.     var    dom=document.getElementById
  26.  
  27.     var    ns4=document.layers
  28.     var    today =    new    Date()
  29.     var    dateNow     = today.getDate()
  30.     var    monthNow = today.getMonth()
  31.     var    yearNow     = today.getYear()
  32.     var    imgsrc = new Array("drop1.gif","drop2.gif","left1.gif","left2.gif","right1.gif","right2.gif")
  33.     var    img    = new Array()
  34.  
  35.     var bShow = false;
  36.  
  37.     /* hides <select> and <applet> objects (for IE only) */
  38.     function hideElement( elmID, overDiv )
  39.     {
  40.       if( ie )
  41.       {
  42.         for( i = 0; i < document.all.tags( elmID ).length; i++ )
  43.         {
  44.           obj = document.all.tags( elmID )[i];
  45.           if( !obj || !obj.offsetParent )
  46.           {
  47.             continue;
  48.           }
  49.       
  50.           // Find the element's offsetTop and offsetLeft relative to the BODY tag.
  51.           objLeft   = obj.offsetLeft;
  52.           objTop    = obj.offsetTop;
  53.           objParent = obj.offsetParent;
  54.           
  55.           while( objParent.tagName.toUpperCase() != "BODY" )
  56.           {
  57.             objLeft  += objParent.offsetLeft;
  58.             objTop   += objParent.offsetTop;
  59.             objParent = objParent.offsetParent;
  60.           }
  61.       
  62.           objHeight = obj.offsetHeight;
  63.           objWidth = obj.offsetWidth;
  64.       
  65.           if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft );
  66.           else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop );
  67.           else if( overDiv.offsetTop >= ( objTop + objHeight ));
  68.           else if( overDiv.offsetLeft >= ( objLeft + objWidth ));
  69.           else
  70.           {
  71.             obj.style.visibility = "hidden";
  72.           }
  73.         }
  74.       }
  75.     }
  76.      
  77.     /*
  78.     * unhides <select> and <applet> objects (for IE only)
  79.     */
  80.     function showElement( elmID )
  81.     {
  82.       if( ie )
  83.       {
  84.         for( i = 0; i < document.all.tags( elmID ).length; i++ )
  85.         {
  86.           obj = document.all.tags( elmID )[i];
  87.           
  88.           if( !obj || !obj.offsetParent )
  89.           {
  90.             continue;
  91.           }
  92.         
  93.           obj.style.visibility = "";
  94.         }
  95.       }
  96.     }
  97.  
  98.     function HolidayRec (d, m, y, desc)
  99.     {
  100.         this.d = d
  101.         this.m = m
  102.         this.y = y
  103.         this.desc = desc
  104.     }
  105.  
  106.     var HolidaysCounter = 0
  107.     var Holidays = new Array()
  108.  
  109.     function addHoliday (d, m, y, desc)
  110.     {
  111.         Holidays[HolidaysCounter++] = new HolidayRec ( d, m, y, desc )
  112.     }
  113.  
  114.     if (dom)
  115.     {
  116.         for    (i=0;i<imgsrc.length;i++)
  117.         {
  118.             img[i] = new Image
  119.             img[i].src = imgDir + imgsrc[i]
  120.         }
  121.         document.write ("<div onclick='bShow=true' id='calendar'    style='z-index:+999;position:absolute;visibility:hidden;'><table    width="+((showWeekNumber==1)?250:220)+" style='font-family:arial;font-size:11px;border-width:1;border-style:solid;border-color:#a0a0a0;font-family:arial; font-size:11px}' bgcolor='#ffffff'><tr bgcolor='#0000aa'><td><table width='"+((showWeekNumber==1)?248:218)+"'><tr><td style='padding:2px;font-family:arial; font-size:11px;'><font color='#ffffff'><B><span id='caption'></span></B></font></td><td align=right><a href='javascript:hideCalendar()'><IMG SRC='"+imgDir+"close.gif' WIDTH='15' HEIGHT='13' BORDER='0' ALT='Close the Calendar'></a></td></tr></table></td></tr><tr><td style='padding:5px' bgcolor=#ffffff><span id='content'></span></td></tr>")
  122.             
  123.         if (showToday==1)
  124.         {
  125.             document.write ("<tr bgcolor=#f0f0f0><td style='padding:5px' align=center><span id='lblToday'></span></td></tr>")
  126.         }
  127.             
  128.         document.write ("</table></div><div id='selectMonth' style='z-index:+999;position:absolute;visibility:hidden;'></div><div id='selectYear' style='z-index:+999;position:absolute;visibility:hidden;'></div>");
  129.     }
  130.  
  131.     var    monthName =    new    Array("January","February","March","April","May","June","July","August","September","October","November","December")
  132.     if (startAt==0)
  133.     {
  134.         dayName = new Array    ("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
  135.     }
  136.     else
  137.     {
  138.         dayName = new Array    ("Mon","Tue","Wed","Thu","Fri","Sat","Sun")
  139.     }
  140.     var    styleAnchor="text-decoration:none;color:black;"
  141.     var    styleLightBorder="border-style:solid;border-width:1px;border-color:#a0a0a0;"
  142.  
  143.     function swapImage(srcImg, destImg){
  144.         if (ie)    { document.getElementById(srcImg).setAttribute("src",imgDir + destImg) }
  145.     }
  146.  
  147.     function init()    {
  148.         if (!ns4)
  149.         {
  150.             if (!ie) { yearNow += 1900    }
  151.  
  152.             crossobj=(dom)?document.getElementById("calendar").style : ie? document.all.calendar : document.calendar
  153.             hideCalendar()
  154.  
  155.             crossMonthObj=(dom)?document.getElementById("selectMonth").style : ie? document.all.selectMonth    : document.selectMonth
  156.  
  157.             crossYearObj=(dom)?document.getElementById("selectYear").style : ie? document.all.selectYear : document.selectYear
  158.  
  159.             monthConstructed=false;
  160.             yearConstructed=false;
  161.  
  162.             if (showToday==1)
  163.             {
  164.                 document.getElementById("lblToday").innerHTML =    todayString + " <a onmousemove='window.status=\""+gotoString+"\"' onmouseout='window.status=\"\"' title='"+gotoString+"' style='"+styleAnchor+"' href='javascript:monthSelected=monthNow;yearSelected=yearNow;constructCalendar();'>"+dayName[(today.getDay()-startAt==-1)?6:(today.getDay()-startAt)]+", " + dateNow + " " + monthName[monthNow].substring(0,3)    + "    " +    yearNow    + "</a>"
  165.             }
  166.  
  167.             sHTML1="<span id='spanLeft'    style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer' onmouseover='swapImage(\"changeLeft\",\"left2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""+scrollLeftMessage+"\"' onclick='javascript:decMonth()' onmouseout='clearInterval(intervalID1);swapImage(\"changeLeft\",\"left1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartDecMonth()\",500)'    onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'> <IMG id='changeLeft' SRC='"+imgDir+"left1.gif' width=10 height=11 BORDER=0> </span> "
  168.             sHTML1+="<span id='spanRight' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer'    onmouseover='swapImage(\"changeRight\",\"right2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""+scrollRightMessage+"\"' onmouseout='clearInterval(intervalID1);swapImage(\"changeRight\",\"right1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"' onclick='incMonth()' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartIncMonth()\",500)'    onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'> <IMG id='changeRight' SRC='"+imgDir+"right1.gif'    width=10 height=11 BORDER=0> </span> "
  169.             sHTML1+="<span id='spanMonth' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer'    onmouseover='swapImage(\"changeMonth\",\"drop2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""+selectMonthMessage+"\"' onmouseout='swapImage(\"changeMonth\",\"drop1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"' onclick='popUpMonth()'></span> "
  170.             sHTML1+="<span id='spanYear' style='border-style:solid;border-width:1;border-color:#3366FF;cursor:pointer' onmouseover='swapImage(\"changeYear\",\"drop2.gif\");this.style.borderColor=\"#88AAFF\";window.status=\""+selectYearMessage+"\"'    onmouseout='swapImage(\"changeYear\",\"drop1.gif\");this.style.borderColor=\"#3366FF\";window.status=\"\"'    onclick='popUpYear()'></span> "
  171.             
  172.             document.getElementById("caption").innerHTML  =    sHTML1
  173.  
  174.             bPageLoaded=true
  175.         }
  176.     }
  177.  
  178.     function hideCalendar()    {
  179.         crossobj.visibility="hidden"
  180.         if (crossMonthObj != null){crossMonthObj.visibility="hidden"}
  181.         if (crossYearObj !=    null){crossYearObj.visibility="hidden"}
  182.  
  183.         showElement( 'SELECT' );
  184.         showElement( 'APPLET' );
  185.     }
  186.  
  187.     function padZero(num) {
  188.         return (num    < 10)? '0' + num : num ;
  189.     }
  190.  
  191.     function constructDate(d,m,y)
  192.     {
  193.         sTmp = dateFormat
  194.         sTmp = sTmp.replace    ("dd","<e>")
  195.         sTmp = sTmp.replace    ("d","<d>")
  196.         sTmp = sTmp.replace    ("<e>",padZero(d))
  197.         sTmp = sTmp.replace    ("<d>",d)
  198.         sTmp = sTmp.replace    ("mmm","<o>")
  199.         sTmp = sTmp.replace    ("mm","<n>")
  200.         sTmp = sTmp.replace    ("m","<m>")
  201.         sTmp = sTmp.replace    ("<m>",m+1)
  202.         sTmp = sTmp.replace    ("<n>",padZero(m+1))
  203.         sTmp = sTmp.replace    ("<o>",monthName[m])
  204.         return sTmp.replace ("yyyy",y)
  205.     }
  206.  
  207.     function closeCalendar() {
  208.         var    sTmp
  209.  
  210.         hideCalendar();
  211.         ctlToPlaceValue.value =    constructDate(dateSelected,monthSelected,yearSelected)
  212.     }
  213.  
  214.     /*** Month Pulldown    ***/
  215.  
  216.     function StartDecMonth()
  217.     {
  218.         intervalID1=setInterval("decMonth()",80)
  219.     }
  220.  
  221.     function StartIncMonth()
  222.     {
  223.         intervalID1=setInterval("incMonth()",80)
  224.     }
  225.  
  226.     function incMonth () {
  227.         monthSelected++
  228.         if (monthSelected>11) {
  229.             monthSelected=0
  230.             yearSelected++
  231.         }
  232.         constructCalendar()
  233.     }
  234.  
  235.     function decMonth () {
  236.         monthSelected--
  237.         if (monthSelected<0) {
  238.             monthSelected=11
  239.             yearSelected--
  240.         }
  241.         constructCalendar()
  242.     }
  243.  
  244.     function constructMonth() {
  245.         popDownYear()
  246.         if (!monthConstructed) {
  247.             sHTML =    ""
  248.             for    (i=0; i<12;    i++) {
  249.                 sName =    monthName[i];
  250.                 if (i==monthSelected){
  251.                     sName =    "<B>" +    sName +    "</B>"
  252.                 }
  253.                 sHTML += "<tr><td id='m" + i + "' onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='monthConstructed=false;monthSelected=" + i + ";constructCalendar();popDownMonth();event.cancelBubble=true'> " + sName + " </td></tr>"
  254.             }
  255.  
  256.             document.getElementById("selectMonth").innerHTML = "<table width=70    style='font-family:arial; font-size:11px; border-width:1; border-style:solid; border-color:#a0a0a0;' bgcolor='#FFFFDD' cellspacing=0 onmouseover='clearTimeout(timeoutID1)'    onmouseout='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"popDownMonth()\",100);event.cancelBubble=true'>" +    sHTML +    "</table>"
  257.  
  258.             monthConstructed=true
  259.         }
  260.     }
  261.  
  262.     function popUpMonth() {
  263.         constructMonth()
  264.         crossMonthObj.visibility = (dom||ie)? "visible"    : "show"
  265.         crossMonthObj.left = parseInt(crossobj.left) + 50
  266.         crossMonthObj.top =    parseInt(crossobj.top) + 26
  267.  
  268.         hideElement( 'SELECT', document.getElementById("selectMonth") );
  269.         hideElement( 'APPLET', document.getElementById("selectMonth") );            
  270.     }
  271.  
  272.     function popDownMonth()    {
  273.         crossMonthObj.visibility= "hidden"
  274.     }
  275.  
  276.     /*** Year Pulldown ***/
  277.  
  278.     function incYear() {
  279.         for    (i=0; i<7; i++){
  280.             newYear    = (i+nStartingYear)+1
  281.             if (newYear==yearSelected)
  282.             { txtYear =    " <B>"    + newYear +    "</B> " }
  283.             else
  284.             { txtYear =    " " + newYear + " " }
  285.             document.getElementById("y"+i).innerHTML = txtYear
  286.         }
  287.         nStartingYear ++;
  288.         bShow=true
  289.     }
  290.  
  291.     function decYear() {
  292.         for    (i=0; i<7; i++){
  293.             newYear    = (i+nStartingYear)-1
  294.             if (newYear==yearSelected)
  295.             { txtYear =    " <B>"    + newYear +    "</B> " }
  296.             else
  297.             { txtYear =    " " + newYear + " " }
  298.             document.getElementById("y"+i).innerHTML = txtYear
  299.         }
  300.         nStartingYear --;
  301.         bShow=true
  302.     }
  303.  
  304.     function selectYear(nYear) {
  305.         yearSelected=parseInt(nYear+nStartingYear);
  306.         yearConstructed=false;
  307.         constructCalendar();
  308.         popDownYear();
  309.     }
  310.  
  311.     function constructYear() {
  312.         popDownMonth()
  313.         sHTML =    ""
  314.         if (!yearConstructed) {
  315.  
  316.             sHTML =    "<tr><td align='center'    onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='clearInterval(intervalID1);this.style.backgroundColor=\"\"' style='cursor:pointer'    onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"decYear()\",30)' onmouseup='clearInterval(intervalID1)'>-</td></tr>"
  317.  
  318.             j =    0
  319.             nStartingYear =    yearSelected-3
  320.             for    (i=(yearSelected-3); i<=(yearSelected+3); i++) {
  321.                 sName =    i;
  322.                 if (i==yearSelected){
  323.                     sName =    "<B>" +    sName +    "</B>"
  324.                 }
  325.  
  326.                 sHTML += "<tr><td id='y" + j + "' onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='selectYear("+j+");event.cancelBubble=true'> " + sName + " </td></tr>"
  327.                 j ++;
  328.             }
  329.  
  330.             sHTML += "<tr><td align='center' onmouseover='this.style.backgroundColor=\"#FFCC99\"' onmouseout='clearInterval(intervalID2);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\"incYear()\",30)'    onmouseup='clearInterval(intervalID2)'>+</td></tr>"
  331.  
  332.             document.getElementById("selectYear").innerHTML    = "<table width=44 style='font-family:arial; font-size:11px; border-width:1; border-style:solid; border-color:#a0a0a0;'    bgcolor='#FFFFDD' onmouseover='clearTimeout(timeoutID2)' onmouseout='clearTimeout(timeoutID2);timeoutID2=setTimeout(\"popDownYear()\",100)' cellspacing=0>"    + sHTML    + "</table>"
  333.  
  334.             yearConstructed    = true
  335.         }
  336.     }
  337.  
  338.     function popDownYear() {
  339.         clearInterval(intervalID1)
  340.         clearTimeout(timeoutID1)
  341.         clearInterval(intervalID2)
  342.         clearTimeout(timeoutID2)
  343.         crossYearObj.visibility= "hidden"
  344.     }
  345.  
  346.     function popUpYear() {
  347.         var    leftOffset
  348.  
  349.         constructYear()
  350.         crossYearObj.visibility    = (dom||ie)? "visible" : "show"
  351.         leftOffset = parseInt(crossobj.left) + document.getElementById("spanYear").offsetLeft
  352.         if (ie)
  353.         {
  354.             leftOffset += 6
  355.         }
  356.         crossYearObj.left =    leftOffset
  357.         crossYearObj.top = parseInt(crossobj.top) +    26
  358.     }
  359.  
  360.     /*** calendar ***/
  361.    function WeekNbr(n) {
  362.       // Algorithm used:
  363.       // From Klaus Tondering's Calendar document (The Authority/Guru)
  364.       // hhtp://www.tondering.dk/claus/calendar.html
  365.       // a = (14-month) / 12
  366.       // y = year + 4800 - a
  367.       // m = month + 12a - 3
  368.       // J = day + (153m + 2) / 5 + 365y + y / 4 - y / 100 + y / 400 - 32045
  369.       // d4 = (J + 31741 - (J mod 7)) mod 146097 mod 36524 mod 1461
  370.       // L = d4 / 1460
  371.       // d1 = ((d4 - L) mod 365) + L
  372.       // WeekNumber = d1 / 7 + 1
  373.  
  374.       year = n.getFullYear();
  375.       month = n.getMonth() + 1;
  376.       if (startAt == 0) {
  377.          day = n.getDate() + 1;
  378.       }
  379.       else {
  380.          day = n.getDate();
  381.       }
  382.  
  383.       a = Math.floor((14-month) / 12);
  384.       y = year + 4800 - a;
  385.       m = month + 12 * a - 3;
  386.       b = Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400);
  387.       J = day + Math.floor((153 * m + 2) / 5) + 365 * y + b - 32045;
  388.       d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461;
  389.       L = Math.floor(d4 / 1460);
  390.       d1 = ((d4 - L) % 365) + L;
  391.       week = Math.floor(d1/7) + 1;
  392.  
  393.       return week;
  394.    }
  395.  
  396.     function constructCalendar () {
  397.         var aNumDays = Array (31,0,31,30,31,30,31,31,30,31,30,31)
  398.  
  399.         var dateMessage
  400.         var    startDate =    new    Date (yearSelected,monthSelected,1)
  401.         var endDate
  402.  
  403.         if (monthSelected==1)
  404.         {
  405.             endDate    = new Date (yearSelected,monthSelected+1,1);
  406.             endDate    = new Date (endDate    - (24*60*60*1000));
  407.             numDaysInMonth = endDate.getDate()
  408.         }
  409.         else
  410.         {
  411.             numDaysInMonth = aNumDays[monthSelected];
  412.         }
  413.  
  414.         datePointer    = 0
  415.         dayPointer = startDate.getDay() - startAt
  416.         
  417.         if (dayPointer<0)
  418.         {
  419.             dayPointer = 6
  420.         }
  421.  
  422.         sHTML =    "<table     border=0 style='font-family:verdana;font-size:10px;'><tr>"
  423.  
  424.         if (showWeekNumber==1)
  425.         {
  426.             sHTML += "<td width=27><b>" + weekString + "</b></td><td width=1 rowspan=7 bgcolor='#d0d0d0' style='padding:0px'><img src='"+imgDir+"divider.gif' width=1></td>"
  427.         }
  428.  
  429.         for    (i=0; i<7; i++)    {
  430.             sHTML += "<td width='27' align='right'><B>"+ dayName[i]+"</B></td>"
  431.         }
  432.         sHTML +="</tr><tr>"
  433.         
  434.         if (showWeekNumber==1)
  435.         {
  436.             sHTML += "<td align=right>" + WeekNbr(startDate) + " </td>"
  437.         }
  438.  
  439.         for    ( var i=1; i<=dayPointer;i++ )
  440.         {
  441.             sHTML += "<td> </td>"
  442.         }
  443.     
  444.         for    ( datePointer=1; datePointer<=numDaysInMonth; datePointer++ )
  445.         {
  446.             dayPointer++;
  447.             sHTML += "<td align=right>"
  448.             sStyle=styleAnchor
  449.             if ((datePointer==odateSelected) &&    (monthSelected==omonthSelected)    && (yearSelected==oyearSelected))
  450.             { sStyle+=styleLightBorder }
  451.  
  452.             sHint = ""
  453.             for (k=0;k<HolidaysCounter;k++)
  454.             {
  455.                 if ((parseInt(Holidays[k].d)==datePointer)&&(parseInt(Holidays[k].m)==(monthSelected+1)))
  456.                 {
  457.                     if ((parseInt(Holidays[k].y)==0)||((parseInt(Holidays[k].y)==yearSelected)&&(parseInt(Holidays[k].y)!=0)))
  458.                     {
  459.                         sStyle+="background-color:#FFDDDD;"
  460.                         sHint+=sHint==""?Holidays[k].desc:"\n"+Holidays[k].desc
  461.                     }
  462.                 }
  463.             }
  464.  
  465.             var regexp= /\"/g
  466.             sHint=sHint.replace(regexp,""")
  467.  
  468.             dateMessage = "onmousemove='window.status=\""+selectDateMessage.replace("[date]",constructDate(datePointer,monthSelected,yearSelected))+"\"' onmouseout='window.status=\"\"' "
  469.  
  470.             if ((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow))
  471.             { sHTML += "<b><a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer+";closeCalendar();'><font color=#ff0000> " + datePointer + "</font> </a></b>"}
  472.             else if    (dayPointer % 7 == (startAt * -1)+1)
  473.             { sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer + ";closeCalendar();'> <font color=#909090>" + datePointer + "</font> </a>" }
  474.             else
  475.             { sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer + ";closeCalendar();'> " + datePointer + " </a>" }
  476.  
  477.             sHTML += ""
  478.             if ((dayPointer+startAt) % 7 == startAt) { 
  479.                 sHTML += "</tr><tr>" 
  480.                 if ((showWeekNumber==1)&&(datePointer<numDaysInMonth))
  481.                 {
  482.                     sHTML += "<td align=right>" + (WeekNbr(new Date(yearSelected,monthSelected,datePointer+1))) + " </td>"
  483.                 }
  484.             }
  485.         }
  486.  
  487.         document.getElementById("content").innerHTML   = sHTML
  488.         document.getElementById("spanMonth").innerHTML = " " +    monthName[monthSelected] + " <IMG id='changeMonth' SRC='"+imgDir+"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
  489.         document.getElementById("spanYear").innerHTML =    " " + yearSelected    + " <IMG id='changeYear' SRC='"+imgDir+"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
  490.     }
  491.  
  492.     function popUpCalendar(ctl,    ctl2, format) {
  493.         var    leftpos=0
  494.         var    toppos=0
  495.  
  496.         if (bPageLoaded)
  497.         {
  498.             if ( crossobj.visibility ==    "hidden" ) {
  499.                 ctlToPlaceValue    = ctl2
  500.                 dateFormat=format;
  501.  
  502.                 formatChar = " "
  503.                 aFormat    = dateFormat.split(formatChar)
  504.                 if (aFormat.length<3)
  505.                 {
  506.                     formatChar = "/"
  507.                     aFormat    = dateFormat.split(formatChar)
  508.                     if (aFormat.length<3)
  509.                     {
  510.                         formatChar = "."
  511.                         aFormat    = dateFormat.split(formatChar)
  512.                         if (aFormat.length<3)
  513.                         {
  514.                             formatChar = "-"
  515.                             aFormat    = dateFormat.split(formatChar)
  516.                             if (aFormat.length<3)
  517.                             {
  518.                                 // invalid date    format
  519.                                 formatChar=""
  520.                             }
  521.                         }
  522.                     }
  523.                 }
  524.  
  525.                 tokensChanged =    0
  526.                 if ( formatChar    != "" )
  527.                 {
  528.                     // use user's date
  529.                     aData =    ctl2.value.split(formatChar)
  530.  
  531.                     for    (i=0;i<3;i++)
  532.                     {
  533.                         if ((aFormat[i]=="d") || (aFormat[i]=="dd"))
  534.                         {
  535.                             dateSelected = parseInt(aData[i], 10)
  536.                             tokensChanged ++
  537.                         }
  538.                         else if    ((aFormat[i]=="m") || (aFormat[i]=="mm"))
  539.                         {
  540.                             monthSelected =    parseInt(aData[i], 10) - 1
  541.                             tokensChanged ++
  542.                         }
  543.                         else if    (aFormat[i]=="yyyy")
  544.                         {
  545.                             yearSelected = parseInt(aData[i], 10)
  546.                             tokensChanged ++
  547.                         }
  548.                         else if    (aFormat[i]=="mmm")
  549.                         {
  550.                             for    (j=0; j<12;    j++)
  551.                             {
  552.                                 if (aData[i]==monthName[j])
  553.                                 {
  554.                                     monthSelected=j
  555.                                     tokensChanged ++
  556.                                 }
  557.                             }
  558.                         }
  559.                     }
  560.                 }
  561.  
  562.                 if ((tokensChanged!=3)||isNaN(dateSelected)||isNaN(monthSelected)||isNaN(yearSelected))
  563.                 {
  564.                     dateSelected = dateNow
  565.                     monthSelected =    monthNow
  566.                     yearSelected = yearNow
  567.                 }
  568.  
  569.                 odateSelected=dateSelected
  570.                 omonthSelected=monthSelected
  571.                 oyearSelected=yearSelected
  572.  
  573.                 aTag = ctl
  574.                 do {
  575.                     aTag = aTag.offsetParent;
  576.                     leftpos    += aTag.offsetLeft;
  577.                     toppos += aTag.offsetTop;
  578.                 } while(aTag.tagName!="BODY");
  579.  
  580.                 crossobj.left =    fixedX==-1 ? ctl.offsetLeft    + leftpos :    fixedX
  581.                 crossobj.top = fixedY==-1 ?    ctl.offsetTop +    toppos + ctl.offsetHeight +    2 :    fixedY
  582.                 constructCalendar (1, monthSelected, yearSelected);
  583.                 crossobj.visibility=(dom||ie)? "visible" : "show"
  584.  
  585.                 hideElement( 'SELECT', document.getElementById("calendar") );
  586.                 hideElement( 'APPLET', document.getElementById("calendar") );            
  587.  
  588.                 bShow = true;
  589.             }
  590.             else
  591.             {
  592.                 hideCalendar()
  593.                 if (ctlNow!=ctl) {popUpCalendar(ctl, ctl2, format)}
  594.             }
  595.             ctlNow = ctl
  596.         }
  597.     }
  598.  
  599.     document.onkeypress = function hidecal1 () { 
  600.         if (event.keyCode==27) 
  601.         {
  602.             hideCalendar()
  603.         }
  604.     }
  605.     document.onclick = function hidecal2 () {         
  606.         if (!bShow)
  607.         {
  608.             hideCalendar()
  609.         }
  610.         bShow = false
  611.     }
  612.  
  613.     init()